package com.frank.oj.controller.msg;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.frank.oj.common.result.CommonResult;
import com.frank.oj.model.vo.UserMsgVO;
import com.frank.oj.model.vo.UserUnreadMsgCountVO;
import com.frank.oj.service.msg.UserMessageService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 信息
 * @author frank
 * @Date 2024/1/25
 */
@RestController
@RequestMapping("/api/msg")
public class UserMessageController {

    @Resource
    private UserMessageService userMessageService;

    /**
     * 获取未读消息数量,包括评论我的、回复我的、收到的赞、系统通知、我的消息
     */
    @GetMapping("/unread")
    @RequiresAuthentication
    public CommonResult<UserUnreadMsgCountVO> getUnreadMsgCount(){
        return userMessageService.getUnreadMsgCount();
    }

    /**
     *  获取点赞我的的消息
     */
    @GetMapping("/like")
    @RequiresAuthentication
    public CommonResult<IPage<UserMsgVO>> getLikeMsg(@RequestParam(value = "limit", required = false) Integer limit,
                                                     @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return userMessageService.getLikeMsg(limit, currentPage);
    }

    /**
     *  获取评论我的的消息
     */
    @GetMapping("/comment")
    @RequiresAuthentication
    public CommonResult<IPage<UserMsgVO>> getCommentMsg(@RequestParam(value = "limit", required = false) Integer limit,
                                                        @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return userMessageService.getCommentMsg(limit, currentPage);
    }

    /**
     *  获取回复我的的消息
     */
    @GetMapping("/reply")
    @RequiresAuthentication
    public CommonResult<IPage<UserMsgVO>> getReplyMsg(@RequestParam(value = "limit", required = false) Integer limit,
                                                      @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return userMessageService.getReplyMsg(limit, currentPage);
    }

    /**
     *  清理消息
     */
    @DeleteMapping("/clean")
    @RequiresAuthentication
    public CommonResult<Void> cleanMsg(@RequestParam("type") String type,
                                       @RequestParam(value = "id", required = false) Long id) {
        return userMessageService.cleanMsg(type, id);
    }
}
